package com.woniu.controller;

import com.woniu.entity.Supplier;
import com.woniu.service.SupplierService;
import com.woniu.util.ResponseUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/suppliers")
@CrossOrigin
public class SupplierController {

    @Resource
    private SupplierService supplierService;

    // 获取所有供应商
    @GetMapping("/findAll")
    public ResponseUtil getAllSuppliers() {
        return supplierService.getAllSuppliers();
    }

    // 根据ID获取供应商
    @GetMapping("/findById/{id}")
    public ResponseUtil getSupplierById(@PathVariable Integer id) {
        return supplierService.getSupplierById(id);
    }

    // 添加供应商
    @PostMapping("/add")
    public ResponseUtil addSupplier(@RequestBody Supplier supplier) {
        return supplierService.addSupplier(supplier);
    }

    // 修改供应商
    @PutMapping("/update")
    public ResponseUtil updateSupplier(@RequestBody Supplier supplier) {
        return supplierService.updateSupplier(supplier);
    }

    // 冻结/解冻供应商
    @PutMapping("/freeze/{id}")
    public ResponseUtil freezeSupplier(
            @PathVariable Integer id,
            @RequestParam Integer status) {
        return supplierService.freezeSupplier(id, status);
    }

    // 删除供应商
    @DeleteMapping("/delete/{id}")
    public ResponseUtil deleteSupplier(@PathVariable Integer id) {
        return supplierService.deleteSupplier(id);
    }

    // 搜索供应商
    @GetMapping("/search")
    public ResponseUtil searchSuppliers(@RequestParam String keyword) {
        return supplierService.searchSuppliers(keyword);
    }
}
